package com.m3958.firstgwt.server.service;

import java.util.HashMap;
import java.util.Map;

public class ObjectKeyValueProcessor {
	
	public static interface HasKeyValue{
		public String getKeyValues();
		public void setKeyValueMap(Map<String, String> keyValueMap);
		public Map<String, String> getKeyValueMap();
	}
	
	public static String getValue(HasKeyValue hkv,String key){
		String keyValues = hkv.getKeyValues();
		if(keyValues == null || keyValues.isEmpty())return "";
		if(hkv.getKeyValueMap() == null){
			hkv.setKeyValueMap(new HashMap<String, String>());
			keyValues = keyValues.replaceAll("，", ",");
			String[] kvs = keyValues.split(",");
			for(String kv : kvs){
				String[] kk = kv.split("=");
				if(kk.length == 1){
					hkv.getKeyValueMap().put(kk[0], "");
				}else{
					hkv.getKeyValueMap().put(kk[0], kk[1]);
				}
			}
		}
		String s = hkv.getKeyValueMap().get(key); 
		return s == null ? "" : s;
	}
	
}
